# Contributor: Michael John <gosh.mike@gmail.com>
# Maintainer: Michael John <gosh.mike@gmail.com>
pkgname=azure-iot-sdk-c-static
pkgver=1.11.0
pkgrel=0
pkgdesc="Azure IoT SDK"
url="https://github.com/Azure/azure-iot-sdk-c"
arch="all"
license="MIT"
options="!check" # make check not implemented
makedepends="cmake openssl-dev openssl-libs-static libcurl curl-dev libuuid util-linux-dev busybox"
_azure_c_shared_utility_commit="4f1b7cd6bf48833fe4b9e23e2ff07510753faee5"
_azure_umqtt_c_commit="9201d60bbc12a02ac5456b6105bb50919d392105"
_azure_uamqp_c_commit="b7bdf307a0db8840156d9f6e40f704c1d5924306"
_parson_commit="4158fdbea7da5a7c7efb182b69707c78f35a398f"
_uhttp_commit="33485e2e43f9c8f186dfff8afda7efd905b636f1"
_riot_commit="f6bebff2f5a68f5bc18d23ed164800db33b7d2a4"
_utpm_commit="4fc2aa8717f15ad22e4cd9571d2784cef25932be"
_azure_macro_utils_c_commit="5926caf4e42e98e730e6d03395788205649a3ada"
_umock_c_commit="504193e65d1c2f6eb50c15357167600a296df7ff"
_azure_c_testrunnerswitcher_commit="8734bd6c53c88dd6c0cea8e87d70b9964726484a"
_azure_ctest_commit="4aa84c45236ecda21983fb682f542f17d0b21e19"
source="$pkgname-$pkgver.tar.gz::https://github.com/Azure/azure-iot-sdk-c/archive/$pkgver.tar.gz
	$pkgname-$pkgver-azure_c_shared_utility.tar.gz::https://github.com/Azure/azure-c-shared-utility/archive/$_azure_c_shared_utility_commit.tar.gz
	$pkgname-$pkgver-azure_umqtt_c.tar.gz::https://github.com/Azure/azure-umqtt-c/archive/$_azure_umqtt_c_commit.tar.gz
	$pkgname-$pkgver-azure_uamqp_c.tar.gz::https://github.com/Azure/azure-uamqp-c/archive/$_azure_uamqp_c_commit.tar.gz
	$pkgname-$pkgver-parson.tar.gz::https://github.com/kgabis/parson/archive/$_parson_commit.tar.gz
	$pkgname-$pkgver-uhttp.tar.gz::https://github.com/Azure/azure-uhttp-c/archive/$_uhttp_commit.tar.gz
	$pkgname-$pkgver-riot.tar.gz::https://github.com/Microsoft/RIoT/archive/$_riot_commit.tar.gz
	$pkgname-$pkgver-utpm.tar.gz::https://github.com/Azure/azure-utpm-c/archive/$_utpm_commit.tar.gz
	$pkgname-$pkgver-macro_utils_c.tar.gz::https://github.com/Azure/macro-utils-c/archive/$_azure_macro_utils_c_commit.tar.gz
	$pkgname-$pkgver-umock_c.tar.gz::https://github.com/Azure/umock-c/archive/$_umock_c_commit.tar.gz
	$pkgname-$pkgver-c_testrunnerswitcher.tar.gz::https://github.com/Azure/c-testrunnerswitcher/archive/$_azure_c_testrunnerswitcher_commit.tar.gz
	$pkgname-$pkgver-ctest.tar.gz::https://github.com/Azure/azure-ctest/archive/$_azure_ctest_commit.tar.gz
	"
builddir="$srcdir/${pkgname%-static}-$pkgver"

prepare() {
	# adding submodules needed by azure-iot-sdk-c
	mv "$srcdir"/azure-c-shared-utility-$_azure_c_shared_utility_commit/* "$builddir"/c-utility/
	mv "$srcdir"/azure-umqtt-c-$_azure_umqtt_c_commit/* "$builddir"/umqtt/
	mv "$srcdir"/azure-uamqp-c-$_azure_uamqp_c_commit/* "$builddir"/uamqp/
	mv "$srcdir"/parson-$_parson_commit/* "$builddir"/deps/parson/
	mv "$srcdir"/azure-uhttp-c-$_uhttp_commit/* "$builddir"/deps/uhttp/
	mv "$srcdir"/RIoT-$_riot_commit/* "$builddir"/provisioning_client/deps/RIoT/
	mv "$srcdir"/azure-utpm-c-$_utpm_commit/* "$builddir"/provisioning_client/deps/utpm/
	mv "$srcdir"/macro-utils-c-$_azure_macro_utils_c_commit/* "$builddir"/deps/azure-macro-utils-c/
	mv "$srcdir"/umock-c-$_umock_c_commit/* "$builddir"/deps/umock-c/
	mv "$srcdir"/c-testrunnerswitcher-$_azure_c_testrunnerswitcher_commit/* "$builddir"/deps/azure-c-testrunnerswitcher/
	mv "$srcdir"/ctest-$_azure_ctest_commit/* "$builddir"/deps/azure-ctest/

	default_prepare
}

build() {
	mkdir -p cmake-build
	cd cmake-build

	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-Duse_amqp=OFF \
		${CMAKE_CROSSOPTS} ..
	cmake --build .
}

package() {
	cd "$builddir"/cmake-build
	make DESTDIR="$pkgdir" install

	mv "$pkgdir"/usr/cmake "$pkgdir"/usr/lib/cmake
}

sha512sums="
7e78e4bded0d4b7acebc863350c451d40067d97112edf465efb99057e18854c279b40798fddd07051987f5abd1d9a7f220b3a7d108e0e1c35adae96ef6b73615  azure-iot-sdk-c-static-1.11.0.tar.gz
5374585bd05ad2b55d2aa183d65b0b371d52b7f3145bcc9486e92d306d172109a8a6b13e14b56073426c3b02541044864d63fc728a9006a8dcd7ab552002be79  azure-iot-sdk-c-static-1.11.0-azure_c_shared_utility.tar.gz
97d5383184c99186783738613d00e77041fe4ff3af4c14fe775e4be8b38a77a69d093ed8636a67ee85e8e09c8732b8839375aa178128f1ae58792d7c8698f829  azure-iot-sdk-c-static-1.11.0-azure_umqtt_c.tar.gz
a23ddab35caa6f9303072f235591d64f5cfe3c2f4a16e9f317380a9d887f47f146b0bca5afcb2e3a199b146e8092192ede2ec68685edb8a7fb11cfe5641815b8  azure-iot-sdk-c-static-1.11.0-azure_uamqp_c.tar.gz
52854bb2cdc890c0abf7c9eec2cb0dbc5452bc78c73b1364cb3ef8d37d636f41335e58a11f7fe6faae762dea3bee24ddccb020bc188229db143cf5e871f6f149  azure-iot-sdk-c-static-1.11.0-parson.tar.gz
ad9c8f21cee431ac39a5ffc5f1007b76c5ba1768dca6cebf8fceda33747c3accbce48ace72173cfe746316a0a136a7e770005ba98b8f99e5bb3889b5bdc2e973  azure-iot-sdk-c-static-1.11.0-uhttp.tar.gz
5d07bc934ab8d64c2bc930636fe135e677cac6bd6ae85ca6028eb4a28ef5776d6326bdd1f654646597a169f7da8e36318ea36496523052a826686aa1d959c967  azure-iot-sdk-c-static-1.11.0-riot.tar.gz
cef3cb9c5578a88f0839f68429da72ac40f8f82cace53cf0ab93e9a8dcb546fab23f16c51bec960edf83fdbde92a069c72e9d8f794d891f6408a991a6e871ee6  azure-iot-sdk-c-static-1.11.0-utpm.tar.gz
8f9fd02012202db6cff5b647edbc8332a2c03963e80182a630af6a884f23df96b8e24d60e5412bfc2a0a7f43240a54f9597040aa28a9d3e1566755e1d52aac62  azure-iot-sdk-c-static-1.11.0-macro_utils_c.tar.gz
68d5d986314dbd46d20de2a9b9454154c11675c25d1b5a5b1cfecdd0c0945d9dc68d0348ec1dbb00b5d1a6a1f0356121ba561d7c8fffb97ab37864edade5a85b  azure-iot-sdk-c-static-1.11.0-umock_c.tar.gz
0b2d630228d65bf63be8c41ca998de24011165b3dc879a86df6372a253c1bfd9e928672fb0817ca8c036274ed05ef2ee58ec4b7102d3c5bf6222cac452da07d0  azure-iot-sdk-c-static-1.11.0-c_testrunnerswitcher.tar.gz
0bf0ccbb7c63e62beb62b690a9d4d173518bada9987cf7c569c27ab9d843f1f5ca844001a542d617b402637bd16969f22c50361421c39cbfce73d662b9f423bb  azure-iot-sdk-c-static-1.11.0-ctest.tar.gz
"
